#ifndef _QUOTEDPRINTABLEENCODE_HPP_
#define _QUOTEDPRINTABLEENCODE_HPP_

#include "jhdefs.hpp"
#include "stream/streambuf.hpp"
using JHCPP::stream::UnbufferedStreamBuf;
#include <ostream>


NET_NAMESPACE_BEGIN

class CQuotedPrintableEncodeBuf: public UnbufferedStreamBuf
{
public:
	CQuotedPrintableEncodeBuf(std::ostream& ostr);
	~CQuotedPrintableEncodeBuf();
	int close();

private:
	int writeToDevice(char c);
	void writeEncoded(char c);
	void writeRaw(char c);

	int           m_pending;
	int           m_lineLength;
	std::ostream& m_ostr;
};


class CQuotedPrintableEncodeIOS : public virtual std::ios
{
public:
	CQuotedPrintableEncodeIOS(std::ostream& ostr);
	~CQuotedPrintableEncodeIOS();
	int close();
	CQuotedPrintableEncodeBuf* rdbuf();

protected:
	CQuotedPrintableEncodeBuf m_buf;
};


class CQuotedPrintableEncode : public CQuotedPrintableEncodeIOS, public std::ostream
{
public:
	CQuotedPrintableEncode(std::ostream& ostr);
	~CQuotedPrintableEncode();
};



class CQuotedPrintableDecodeBuf : public UnbufferedStreamBuf
{
public:
	CQuotedPrintableDecodeBuf(std::istream& istr);
	~CQuotedPrintableDecodeBuf();

private:
	int readFromDevice();

	std::streambuf& m_buf;
};

class CQuotedPrintableDecodeIOS : public virtual std::ios
{
public:
	CQuotedPrintableDecodeIOS(std::istream& istr);
	~CQuotedPrintableDecodeIOS();
	CQuotedPrintableDecodeBuf* rdbuf();

protected:
	CQuotedPrintableDecodeBuf m_buf;
};

class CQuotedPrintableDecode : public CQuotedPrintableDecodeIOS, public std::istream
{
public:
	CQuotedPrintableDecode(std::istream& istr);
	~CQuotedPrintableDecode();
};


NET_NAMESPACE_END

#endif
